﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using dotUML.System;

namespace dotUML.Core.Common.SequenceDiagram
{
    /// <summary>
    /// Defines the class of a UML sequence diagram.
    /// </summary>
    class SequenceDiagram : DiagramBase, ISequenceDiagram
    {
        Dictionary<string, ILifeline> _lifelines;

        /// <summary>
        /// Diagram's lifelienes.
        /// </summary>
        public Dictionary<string, ILifeline> Lifelines
        {
            get { return _lifelines; }
            set { _lifelines = value; }
        }

        /// <summary>
        /// Class constructor.
        /// </summary>
        public SequenceDiagram()
        {
            Lifelines = new Dictionary<string, ILifeline>();
        }

        #region ISequenceDiagram Members

        /// <summary>
        /// Create a lifeline and add it to the current UML sequence diagram.
        /// Throws an error if an element with the provided name already exists.
        /// </summary>
        /// <param name="Name">Lifeline name.</param>
        /// <param name="LifelineType">Lifeline type.</param>
        /// <returns>Newly created lifeline.</returns>
        public ILifeline AddLifeline(string Name, ELifelineType LifelineType)
        {
            if (Lifelines.ContainsKey(Name))
            {
                throw new CommonException(string.Format(Resources.SequenceDiagram_AddLifeline_AlreadyExists, Name));
            }

            ILifeline result = (ILifeline)InstrumentationManager.InstrumentObject(new Lifeline(Name, LifelineType), EInstrumentationType.Logging);
            Lifelines.Add(Name, result);
            AddElement(result);
            result.ParentDiagram = this;

            return result;
        }

        /// <summary>
        /// Get a lifeline.
        /// </summary>
        /// <param name="Name">Lifeline name.</param>
        /// <returns>Required lifeline or null, if it does not exist.</returns>
        public ILifeline GetLifeline(string Name)
        {
            ILifeline result = null;

            if (Lifelines.ContainsKey(Name))
            {
                result = Lifelines[Name];
            }

            return result;
        }

        /// <summary>
        /// Delete a lifeline. If required lifeline does not exist, does nothing.
        /// </summary>
        /// <param name="Name">Lifeline name.</param>
        public void DeleteLifeline(string Name)
        {
            if (Lifelines.ContainsKey(Name))
            {
                Lifelines.Remove(Name);
            }
        }

        /// <summary>
        /// Collection of lifelines names.
        /// </summary>
        public ICollection<string> LifelinesNames
        {
            get
            {
                return Lifelines.Keys;
            }
        }
        

        public IMessage AddMessage(string Name, EMessageType MessageType, string Source, string Target, bool Async, string Label)
        {
            throw new NotImplementedException();
        }

        public IMessage GetMessage(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteMessage(string Name)
        {
            throw new NotImplementedException();
        }

        public IConstraint AddConstraint(string Name, EConstraintType ConstraintType, string Value, string MessageName)
        {
            throw new NotImplementedException();
        }

        public IConstraint GetConstraint(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteConstraint(string Name)
        {
            throw new NotImplementedException();
        }

        public ICombinedFragmentBase AddCombinedFragment(string Name, ECombinedFragmentType CombinedFragmentType)
        {
            throw new NotImplementedException();
        }

        public ICombinedFragmentBase GetCombinedFragment(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteCombinedFragment(string Name)
        {
            throw new NotImplementedException();
        }

        public IInvariant AddInvariant(string Name, string LifelineName)
        {
            throw new NotImplementedException();
        }

        public IInvariant GetInvariant(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteInvariant(string Name)
        {
            throw new NotImplementedException();
        }

        public IContinuation AddContinuation(string Name, string Value)
        {
            throw new NotImplementedException();
        }

        public IContinuation GetContinuation(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteContinuation(string Name)
        {
            throw new NotImplementedException();
        }

        public IConcurrent AddConcurrent(string Name, string LifelineName)
        {
            throw new NotImplementedException();
        }

        public IConcurrent GetConcurrent(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteConcurrent(string Name)
        {
            throw new NotImplementedException();
        }

        public IReference AddReference(string Name)
        {
            throw new NotImplementedException();
        }

        public IReference GetReference(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteReference(string Name)
        {
            throw new NotImplementedException();
        }

        public IDestruction AddDestruction(string Name)
        {
            throw new NotImplementedException();
        }

        public IDestruction GetDestruction(string Name)
        {
            throw new NotImplementedException();
        }

        public void DeleteDestruction(string Name)
        {
            throw new NotImplementedException();
        }

        public void AddSequenceEntry(string Name)
        {
            throw new NotImplementedException();
        }

        public void NumberMessages()
        {
            throw new NotImplementedException();
        }

        #endregion

    }
}
